#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::add_mes(int index, QString car_id, QString card_id, QString in_time, QString out_time, int fee, QByteArray datagram)
{
    this->car_id = car_id;
    this->card_id = card_id;
    this->in_time = in_time;
    this->out_time = out_time;
    this->fee = fee;

    if(index == 1)
    {
        ui->lineEdit->setText(car_id);
        ui->lineEdit_2->setText(card_id);
        ui->lineEdit_3->setText(in_time);
        ui->lineEdit_4->setText(NULL);
        ui->lineEdit_5->setText(QString::number(fee));
        ui->lineEdit_4->setReadOnly(true);

    }
    if(index == 2)
    {
        ui->lineEdit->setText(car_id);
        ui->lineEdit_2->setText(card_id);
        ui->lineEdit_3->setText(in_time);
        ui->lineEdit_4->setText(out_time);
        ui->lineEdit_5->setText(QString::number(fee));
        ui->lineEdit_4->setReadOnly(false);
    }

    QImage image;
    image.loadFromData(datagram, "JPEG"); // 将JPEG数据转换为QImage
    if (!image.isNull()) {
      ui->label->setPixmap(
          QPixmap::fromImage(image).scaled(765, 623, Qt::KeepAspectRatio));
    }
}

void Dialog::on_pushButton_clicked()
{
    if(ui->radioButton->isChecked())
    {
        QString car_id = ui->lineEdit->text();
        QString card_id = ui->lineEdit_2->text();
        QString in_time = ui->lineEdit_3->text();
        QString out_time = ui->lineEdit_4->text();
        int fee = ui->lineEdit_5->text().toInt();
        emit(send(1,car_id,card_id,in_time,out_time,fee,this->in_time,this->out_time));
    }
    if(ui->radioButton_2->isChecked())
    {
        emit(send(2,car_id,card_id,in_time,out_time,fee,this->in_time,this->out_time));
    }
}
